-- Pierwotny właściciel i twórca kodu: AmaMa
-- Zakaz używania / edycji kodu bez wcześniejszej zgody ze strony właściciela
-- Zakaz wykorzystywania całego lub fragmentów kodu
-- W przypadku złamania powyzszych zasad sprawa zostanie skierowana do sądu pod zarzutem: Naruszenia majątkowych praw autorskich
-- Pierwotnie pełne prawo do używania tego kodu posiada tylko AmaMa

local EventinProgress = false

local marker=createMarker(-4545.39, 2888.53, 11.14-0.90, "cylinder", 1.3, 255, 0, 0,255)

addEventHandler("onMarkerHit", resourceRoot, function(el,md)
	if not md or getElementType(el) ~= "player" then return end
	if source ~= marker then return end
    triggerClientEvent(el, "eventZTP:showGUI", resourceRoot)
end)

addEventHandler("onMarkerLeave", resourceRoot, function(el,md)
	if not md or getElementType(el) ~= "player" then return end
	if source ~= marker then return end
    triggerClientEvent(el, "eventZTP:hideGUI", resourceRoot)
end)

local animationList = {
    {'pijesz'},
    {'taniec'},
    {'taniec2'},
    {'taniec3'},
    {'taniec4'},
    {'taniec5'},
    {'taniec6'},
    {'taniec7'},
    {'taniec8'},
    {'taniec9'},
    {'taniec10'},
    {'taniec11'},
    {'taniec12'},
    {'taniec13'},
    {'taniec14'},
    {'taniec15'},
    {'taniec16'},
    {'taniec17'},
    {'taniec18'},
    {'taniec19'},
    {'taniec20'},
    {'palisz'},
    {'lezysz'},
    {'lezysz2'},
    {'lezysz3'},
    {'lezysz4'},
    {'lezysz5'},
    {'siedzisz'},
    {'siedzisz2'},
    {'siedzisz3'},
    {'klekasz'},
    {'klekasz2'},
    {'czekasz'},
    {'akrobata'},
    {'msza'},
    {'msza2'},
    {'znakkrzyza'},
    {'rzygasz'},
    {'jesz'},
    {'cpun1'},
    {'cpun2'},
    {'cpun3'},
    {'cpun4'},
    {'witasz'},
    {'rozmawiasz'},
    {'rozmawiasz2'},
    {'rozmawiasz3'},
    {'nerwowy'},
    {'piszesz'},
    {'gay'},
    {'gay2'},
    {'gay3'},
    {'wreczasz'},
    {'machasz'},
    {'walisz'},
    {'walisz2'},
    {'sikasz'},
    {'pijany'},
    {'pijany2'},
    {'pijany3'},
    {'rapujesz'},
    {'rapujesz2'},
    {'rapujesz3'},
    {'rapujesz4'},
    {'rapujesz5'},
    {'rapujesz6'},
    {'rapujesz7'},
    {'rapujesz8'},
    {'rolki'},
    {'rolki2'},
    {'umierasz'},
    {'umierasz2'},
    {'bijesz'},
    {'bijesz2'},
    {'bijesz3'},
    {'bijesz4'},
    {'bijesz5'},
    {'wolasz'},
    {'wolasz2'},
    {'wolasz3'},
    {'zatrzymujesz'},
    {'wskazujesz'},
    {'rozgladasz'},
    {'krzyczysz'},
    {'fuckyou'},
    {'tchorz'},
    {'kopiesz'},
    {'kopiesz2'},
    {'kopiesz3'},
    {'wywazasz'},
    {'wywazasz2'},
    {'kieszen'},
    {'celujesz'},
    {'kichasz'},
    {'pocalunek'},
    {'taxi'},
    {'taxi2'},
    {'noga'},
    {'pozegnanie'},
    {'cud'},
    {'cud2'},
    {'delirium'},
    {'delirium2'},
    {'delirium3'},
    {'delirium4'},
    {'delirium5'},
    {'naprawiasz'},
    {'naprawiasz2'},
    {'placzesz'},
    {'kibicujesz'},
    {'kibicujesz2'},
    {'bioenergoterapeuta'},
    {'meteorolog'},
    {'klepiesz'},
    {'cierpisz'},
    {'cierpisz'},
    {'starzec'},
    {'starzec2'},
    {'starzec3'},
    {'reanimujesz'},
    {'myjesz'},
    {'zadowolony'},
    {'zadowolony2'},
    {'zalamany'},
    {'zmeczony'},
    {'ochnie'},
    {'cwaniak1'},
    {'cwaniak2'},
    {'cwaniak3'},
    {'cwaniak4'},
    {'cwaniak5'},
    {'cwaniak6'},
    {'cwaniak7'},
    {'cwaniak8'},
    {'cwaniak9'},
    {'cwaniak10'},
    {'pijak'},
    {'sex1'},
    {'sex2'},
    {'dzwonisz'},
    {'rece'},
    {'taichi'},
    {'predator'},
    {'podkrecasz'},
    {'podsluchujesz'}
}

addCommandHandler("tpztp",function(plr)
    if allowedTP and not getElementData(plr,"player:duty") then
    if getElementDimension(plr) == 0 and getElementInterior(plr) == 0 and not getElementData(plr,"player:memberztp") then
    local x,y,z = getElementPosition(plr)
    setElementData(plr,"player:positionztp",""..x..","..y..","..z.."")
    setElementPosition(plr,-4547.73, 2899.92, 10.60)
    setElementDimension(plr,0)
    setElementInterior(plr,0)
    setElementData(plr,"player:memberztp",true)
    end
    end
end)

addCommandHandler("wyjdz-ztp",function(plr)
    if not getElementData(plr,"player:memberztp") and getElementData(plr,"player:positionztp") then
    local pos = split(getElementData(plr,"player:positionztp"), ",")
    setElementPosition(plr,pos[1],pos[2],pos[3])
    setElementDimension(plr,0)
    setElementInterior(plr,0)
    setElementData(plr,"player:positionztp",nil)
    end
end)
    

addEvent("eventZTP:activetp", true)
addEventHandler("eventZTP:activetp", resourceRoot, function()
    if getElementData(client,"player:admin") then
        if allowedTP then
            allowedTP = nil
            outputChatBox("#ff0000[EVENT ZTP]#ccc000 Teleportacja na event ZTP została dezaktywowana.",client,255,255,255,true)
        else
            allowedTP = true
            outputChatBox("#ff0000[EVENT ZTP]#ccc000 Teleportacja na event ZTP została aktywowana przez #ff0000"..getPlayerName(client).."#ccc000. Użyj komendy #ff0000/tpztp#ccc000 ,aby przenieść się na event.",root,255,255,255,true)
        end
        triggerClientEvent(client, "eventZTP:tpresult", resourceRoot,allowedTP)
    end
end)

addEvent("eventZTP:animation", true)
addEventHandler("eventZTP:animation", resourceRoot, function()
    if EventinProgress then return end
    playersinevent = 0
    local los = math.random(1, #animationList)
    for i,v in pairs(getElementsByType("player")) do
       if getElementData(v,"player:memberztp") then
       playersinevent = playersinevent+1
       end
    end
    setTimer(function()
    if playersinevent < 2 then outputChatBox("#ff0000[ZTP] #ccc000Została tylko jedna osoba.",client,255,255,255,true) return end
    setTimer(function()
        outputChatBox("#ff0000[ZTP] #808080Animacja za 3",v,255,255,255,true)
    end,1000,1)
    setTimer(function()
        outputChatBox("#ff0000[ZTP] #808080Animacja za 2",v,255,255,255,true)
    end,2000,1)
    setTimer(function()
        outputChatBox("#ff0000[ZTP] #808080Animacja za 1",v,255,255,255,true)
    end,3000,1)
    setTimer(function()
        for i,v in pairs(getElementsByType("player")) do
            if getElementData(v,"player:memberztp") then
   if isElementWithinColShape ( v, eventztp ) then              
        outputChatBox("#ff0000[ZTP] #ccc000Animacja do wykonania #ff0000/"..animationList[los][1].."",v,255,255,255,true)
   end
   if getElementData(v,"player:memberztp") then
   setElementData(v,"player:allowAnimation",true)
   setElementData(v,"player:winztp",false) 
   end
end
end
   end,4000,1)
   timerdokonca = setTimer(function()
    for i,v in pairs(getElementsByType("player")) do
        if isElementWithinColShape ( v, eventztp ) then
            outputChatBox("#ff0000[ZTP] #808080Z eventu odpada kilka osób ze względu na przekroczenie czasu na zrobienie animacji.",v,255,255,255,true)
        end
        if getElementData(v,"player:memberztp") and not getElementData(v,"player:winztp") then   
            setElementData(v,"player:memberztp",false)  
        end
    end
   end,34000,1)
   end,500,1)

       winners = 0
       EventinProgress = true
       currentanimation = animationList[los][1]
       limitplayers = playersinevent

end)

eventztp = createColCuboid(-4572.54, 2827.01, -1.67, 52.72058105469,95,22.4)


addEventHandler("onPlayerCommand",root,function(command)
    if isElementWithinColShape ( source, eventztp ) then              
    if (command == currentanimation) then
    setElementData(source,"player:winztp",true) 
    setElementData(source,"player:allowAnimation",false)
    if getElementData(source,"player:winztp") and not getElementData(source,"player:allowAnimation") then
        winners = winners+1
    end
    if tonumber(winners) >= tonumber(limitplayers)-1 then
        for i2,v2 in pairs(getElementsByType("player")) do
            if getElementData(v2,"player:memberztp") and not getElementData(v2,"player:winztp") then
            setElementData(v2,"player:memberztp",false)  
            local players = getElementsWithinColShape( eventztp, "player" )         
            for _, thePlayer in ipairs( players ) do                                   
            outputChatBox("#ff0000[ZTP] #808080Z eventu odpada #ff0000"..(getPlayerName(v2) or "nikt").."",thePlayer,255,255,255,true)
            if isTimer(timerdokonca) then killTimer(timerdokonca) end
            end
            outputChatBox("#ff0000[ZTP]#ff0000 Jeśli chcesz opuścić event użyj komendy #ccc000/wyjdz-ztp",v2,255,255,255,true)
            end
        end 
        EventinProgress = false
    end
    end
    end
end)